/*
 *  Filename:      gsl_memory.h
 *  Author:         Erick Huang<erickhuang1989@gmail.com>
 *  Revised:       2013-06-03
 *  Description:   This module defines the GSL memory control functions.
 *
 *  Copyright (c) Erick Huang. All rights reserved.
 */

#ifndef GSL_MEMORY_H
#define GSL_MEMORY_H

#ifdef __cplusplus
extern "C" {
#endif  /*__cplusplus*/


extern void *gsl_mem_alloc(size_t size);
extern void *gsl_mem_alloc0(size_t size);
extern void  gsl_mem_free(void *ptr);
/* Free the memory, and clear the wild pointer */
#define gsl_mem_free_safe(ptr)				\
do{									        \
	if ((ptr) == NULL)	{					\
		/*printf("free: ptr is NULL\n");*/		\
		break;                 				\
	}                                       \
	/*printf("%p => 0", ptr);*/             	\
	free(ptr);								\
	(ptr) = NULL;							\
}while(0)
extern void *gsl_mem_realloc(void *ptr, size_t size);

#define gsl_mem_new(type,count)	    (type*)gsl_mem_alloc(sizeof(type)*(count))
#define gsl_mem_new0(type,count)	(type*)gsl_mem_alloc0(sizeof(type)*(count))	


extern BOOL_t gsl_isbufset( UINT8 *buf, UINT32 val, UINT32 len );
extern void  *gsl_memdup( const void *src, UINT32 len );








#ifdef __cplusplus
}
#endif  /*__cplusplus*/

#endif  /* GSL_MEMORY_H */